package org.senf.outerspace.galaxy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.senf.outerspace.ships.build.Ship;

public class Galaxy {

	private static Galaxy instance;
	
	private List<Ship> ships;
	private Map<Ship,ShipPosition> positions;
	
	private int sizeX;
	private int sizeY;
	
	public static Galaxy getInstance() {
		if (instance == null) {
			instance = new Galaxy();
		}
		return instance;
	}

	private Galaxy() {
		// Private Constructor
		ships = new ArrayList<Ship>();
		positions = new HashMap<Ship, ShipPosition>();
		sizeX = 20;
		sizeY = 20;
	}
	
	public void updateGalaxy() {
		float frameTime = GameClock.getInstance().getFrameTime();
		for (Ship ship: ships) {
			ShipPosition pos = getPosition(ship);
			float speed = ship.getEngine().getBluePrint().getSpeed();
			pos.x += speed*frameTime;
		}
	}
	
	public void addShip(Ship ship) {
		ships.add(ship);
	}
	
	public List<Ship> getShips() {
		return ships;
	}
	
	public ShipPosition getPosition(Ship ship) {
		return positions.get(ship);
	}
	
	public void setPosition(Ship ship, ShipPosition p) {
		positions.put(ship, p);
	}
	
	public int getSizeX() {
		return sizeX;
	}
	
	public int getSizeY() {
		return sizeY;
	}
}
